package com.shixi.shixitraining.shixitraining.ui.tabapply.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.shixi.shixitraining.shixitraining.R;
import com.shixi.shixitraining.shixitraining.base.BaseActivity;
import com.shixi.shixitraining.shixitraining.http.CallbackImple;
import com.shixi.shixitraining.shixitraining.http.HttpUtil;
import com.shixi.shixitraining.shixitraining.ui.tabapply.entity.TrainDetailBean;
import com.shixi.shixitraining.shixitraining.util.ToastUtil;
import com.shixi.shixitraining.shixitraining.util.UserManager;

import butterknife.ButterKnife;
import retrofit2.Call;

import static com.shixi.shixitraining.shixitraining.constant.Constants.APPLYTRAINDETAIL;

public class TrainApplyDetailActivity extends BaseActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_job_apply_detail);
        ButterKnife.bind(this);
        initTitle();
        Intent intent = getIntent();
        if (intent != null) {
            Bundle bundle = intent.getExtras();
            String number = bundle.getString("number");
            requestTrainDetail(number);
        }
    }

    private void requestTrainDetail(String number) {

        String token = UserManager.getInstance().getToken();
        String userId = UserManager.getInstance().getUserId();
        String url = APPLYTRAINDETAIL+"&userId="+userId+"&token="+token+"&number="+number;
        HttpUtil.getInstance().getApiInterface().applyTrainDetail(url).enqueue(new CallbackImple<TrainDetailBean>() {
            @Override
            public void onError(Call<TrainDetailBean> call, Throwable t) {
                ToastUtil.showShortToast(TrainApplyDetailActivity.this, t.getMessage());
            }

            @Override
            public void onSuccess(Call<TrainDetailBean> call, TrainDetailBean response) {
                if (response.getData() != null) {
                    if (response.getStatus() == 200) {
                        TrainDetailBean.DataBean data = response.getData();
                        String addtime = data.getAddtime();
                        String openclass = data.getOpenclass();
                        String steps = data.getSteps();
                        String stepsCn = data.getStepsCn();
                        String title = data.getTitle();

                        TextView mTitle = (TextView) findViewById(R.id.collect_job_title_tv);
                        TextView mTime = (TextView) findViewById(R.id.job_date_tv);
                        TextView mOpenClass = (TextView) findViewById(R.id.job_collect_time_tv);
                        TextView mSteps = (TextView) findViewById(R.id.commit_list_success);
                        TextView mStepsCn = (TextView) findViewById(R.id.tv_train_des);

                        mTitle.setText(title);
                        mTime.setText(openclass);
                        mOpenClass.setText(addtime);
                        mSteps.setText(steps);
                        mStepsCn.setText(stepsCn);



                    } else {
                        ToastUtil.showShortToast(TrainApplyDetailActivity.this, response.getMsg());
                    }

                } else {
                    ToastUtil.showShortToast(TrainApplyDetailActivity.this, "数据为空");
                }
            }
        });


    }

    private void initTitle() {

        ImageView mBackImg = (ImageView) findViewById(R.id.iv_back);
        mBackImg.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                this.finish();
                break;
        }
    }
}
